//
//  TianQiViewController.m
//  MyProject
//
//  Created by apple on 15/11/2.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "TianQiViewController.h"
#import "AFNetworking.h"
#define SCREENSIZE [UIScreen mainScreen].bounds.size
#define URL @"http://chanyouji.com/wiki/apps/weather/%@"
@interface TianQiViewController (){
    UIActivityIndicatorView *_activity;
    UIWebView *_webView;
    UIView*_bgView;
}

@end

@implementation TianQiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //self.automaticallyAdjustsScrollViewInsets = NO;
    [self createView];
    [self getData];
    [self createNavigationBar:9];
    self.back.text = @"天气";
}
- (void)getData{
    NSString * str = [NSString stringWithFormat:URL,self.ID];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSString *newstr = [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding];

        [_webView loadHTMLString:newstr baseURL:nil];
        [_activity removeFromSuperview];
        [_bgView removeFromSuperview];
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}
- (void)createView{
    _webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:_webView];
    [self createActivity];
}
- (void)createActivity{
    //活动指示器
    _activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    
    _bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 60, 60)];
    _bgView.backgroundColor = [UIColor blackColor];
    _bgView.alpha = 0.8;
    [_bgView addSubview:_activity];
    _bgView.frame = CGRectMake((SCREENSIZE.width - [self width:_bgView]) / 2, (SCREENSIZE.height - [self height:_bgView]) / 2 , [self width:_bgView], [self height:_bgView]);
    

    _activity.frame =CGRectMake ((_bgView.frame.size.width - _activity.frame.size.width) / 2, (_bgView.frame.size.height - _activity.frame.size.height) / 2, _activity.frame.size.width, _activity.frame.size.height);
    [_webView addSubview:_bgView];
    [_activity startAnimating];
}
//宽
- (CGFloat)width:(UIView *)view {
    return view.frame.size.width;
}

//高
- (CGFloat)height:(UIView *)view {
    return view.frame.size.height;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
